//
//  HttpHelper.h
//  MobaoInteraction
//
//  Created by a on 2019/12/26.
//  Copyright © 2019 mobao. All rights reserved.
//

#import <Foundation/Foundation.h>

#import <AFNetworking/AFNetworking.h>
#import "DWKeychainTool.h"
#import "JSON.h"
#import "ResponseModel.h"

typedef NS_ENUM(NSUInteger, ResponseCode) {
    ResponseCodeHttpFailed  = -2,//接口请求失败
    ResponseCodeFormatError = -1,//客户端自定义，接口返回非Dictionary格式
    ResponseCodeSuccessed   = 0,//成功
    ResponseCodeException   = 1,//异常
    ResponseCodeFailed      = 2,//失败
};


NS_ASSUME_NONNULL_BEGIN

@interface HttpHelper : NSObject

@property (nonatomic, strong) AFHTTPSessionManager *manager;

+ (instancetype)sharedInstance;

/**
 服务器初始化
 
 @param server 服务器地址
 @return 服务器
 */
- (id)initWithServer:(NSString *)server;

/**
 发送请求
 
 @param URLString 请求方法
 @param parameters 请求参数
 @param success 成功回调
 @param failure 失败回调
 */
- (void)sendPost:(NSString *)URLString
                    parameters:(NSDictionary *)parameters
                       success:(void (^)(NSURLSessionTask *operation, ResponseModel *responseObject))success
                       failure:(void (^)(NSURLSessionTask *operation, NSError *error))failure;


/**
 发送请求
 
 @param URLString 请求方法
 @param parameters 请求参数
 @param success 成功回调
 @param failure 失败回调
 */
- (void)sendGet:(NSString *)URLString
                   parameters:(NSDictionary *)parameters
                      success:(void (^)(NSURLSessionTask *operation, ResponseModel *responseObject))success
                      failure:(void (^)(NSURLSessionTask *operation, NSError *error))failure;

/**
 发送请求
 
 @param URLString 请求方法
 @param parameters 请求参数
 @param success 成功回调
 @param failure 失败回调
 */
- (void)sendPut:(NSString *)URLString
                   parameters:(NSDictionary *)parameters
                      success:(void (^)(NSURLSessionTask *operation, ResponseModel *responseObject))success
                      failure:(void (^)(NSURLSessionTask *operation, NSError *error))failure;

/**
发送请求

@param URLString 请求方法
@param parameters 请求参数
@param success 成功回调
@param failure 失败回调
@return 请求任务
*/
- (NSURLSessionTask *)sendDelete:(NSString *)URLString
                  parameters:(NSDictionary *)parameters
                     success:(void (^)(NSURLSessionTask *operation, ResponseModel *responseObject))success
                     failure:(void (^)(NSURLSessionTask *operation, NSError *error))failure;


-(void)uploadWithUrl:(NSString *)url withParas:(NSDictionary *)paras withImg:(NSDictionary *)imgDic success:(void (^)(NSURLSessionTask *operation, ResponseModel *responseObject))success
             failure:(void (^)(NSURLSessionTask *operation, NSError *error))failure;


//添加签名参数
- (NSDictionary *)addSign:(NSDictionary *)dictionary;

///**
// 请求通用参数
// */
//- (NSDictionary *)commonParameters;

/**
 取消所有请求
 */
+ (void)cancelAllRequest;

/**
 取消特定请求
 
 @param path 请求方法
 */
+ (void)cancelRequestWithPath:(NSString *)path;
@end

NS_ASSUME_NONNULL_END
